package com.zhuojy.equity.mall.admin.web.controller;

import com.zhuojy.equity.mall.admin.common.entity.TSubject;
import com.zhuojy.equity.mall.admin.common.pojo.JsonResult;
import com.zhuojy.equity.mall.admin.service.TSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 收支科目
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("Subject")
@Api(tags = "收支科目")
public class TSubjectController {
    @Autowired
    private TSubjectService tSubjectService;
    /**
     * 收支科目条查分页
     */
    @ApiOperation(value = "收支科目条查分页", httpMethod = "POST", notes = "收支科目条查分页")
    @RequestMapping("findSubjectPagination")
    public JsonResult findSubjectPagination(@RequestBody TSubject tSubject, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        return tSubjectService.findSubjectPagination(tSubject,pageNum,pageSize);
    }
    /**
     * 收支科目删除
     */
    @ApiOperation(value = "收支科目删除", httpMethod = "POST", notes = "收支科目删除")
    @RequestMapping("deleteSubject")
    public JsonResult deleteSubject(Integer id){
        try {
            tSubjectService.deleteSubject(id);
            return JsonResult.success(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.success(444,"删除失败");
        }

    }
    /**
     * 收支科目新增
     */
    @ApiOperation(value = "收支科目新增", httpMethod = "POST", notes = "收支科目新增")
    @RequestMapping("addSubject")
    public JsonResult addSubject(@RequestBody TSubject tSubject){
        try {
            tSubjectService.addSubject(tSubject);
            return JsonResult.success(200,"新增成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.success(444,"新增失败");
        }
    }
}
